﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using EQT.Dal;
using EQT.Model;
using Common.Logging;

public partial class ChangePass : System.Web.UI.Page
{
    private static readonly ILog log = LogManager.GetCurrentClassLogger();
    private DaTuser dalTuser = DevFuture.Common.WorkContext.AppCtx.GetObject("DaTuser") as DaTuser;
    private UserContext context;


    protected void Page_Load(object sender, EventArgs e)
    {
        context = Session["USER_CONTEXT"] as UserContext;
        OperationResult.Text = "";
        divResult.Visible = false;
    }

    protected void btnChange_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(txtOldPass.Text.Trim()))
        {
            OperationResult.Text = "原密码不能为空！";
            divResult.Visible = true;
            return;
        }
        if (string.IsNullOrEmpty(txtNewPass.Text.Trim()))
        {
            OperationResult.Text = "新密码不能为空！";
            divResult.Visible = true;
            return;
        }
        if (string.IsNullOrEmpty(txtNewPassConfirm.Text.Trim()))
        {
            OperationResult.Text = "请确认新密码！";
            divResult.Visible = true;
            return;
        }
        if (txtNewPassConfirm.Text.Trim()!=txtNewPass.Text.Trim())
        {
            OperationResult.Text = "新密码两次输入不一致！";
            divResult.Visible = true;
            return;
        }


        if (txtOldPass.Text.Trim() != context.TUser.Pwd)
        {
            OperationResult.Text = "原密码不正确！";
            divResult.Visible = true;
            return;
        }

        try
        {
            context.TUser.Pwd = txtNewPass.Text.Trim();
            dalTuser.Update(context.TUser);

            OperationResult.Text = "密码修改成功！";
            divResult.Visible = true;
        }
        catch (Exception ex)
        {
            log.Error(ex);
            OperationResult.Text = "密码修改失败！";
            divResult.Visible = true;
            return;
        }
    }
}
